$(function(){
	$("#saveRole").click(function(){
		var roleName = $("#roleName").val();
		if(!roleName){
			eDialog.alert('请填写角色名称');
			return;
		}
		var roleDesc = $("#roleDesc").val();
		if(!roleDesc){
			eDialog.alert('请填写角色描述');
			return;
		}
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getCheckedNodes(true);
		var privlgRule = "";
		for(var i=0;i<nodes.length;i++){
			privlgRule+=nodes[i].id+",";
		}
		if(!privlgRule){
			eDialog.alert('请选择权限');
			return;
		}
		$.ajax({
			url: GLOBAL.WEBROOT+"/systemRole/updateRole",
	        data:{
	        	roleName:roleName,
	        	roleDesc:roleDesc,
	        	power:privlgRule,
	        	id:$("#roleId").val()
	        },
	        type:"post",
	        dataType:"json",
	        async:true,
		    cache:true,
	        success: function (data){
	        	window.top.location.href =WEB_ROOT+"/systemRole/init";
	        },
	        error:function(XMLHttpRequest, textStatus, errorThrown){
	        	
	        }
		});
	});
});